#!/usr/bin/env python
# coding: utf-8
# %%
import unittest
import os
import shutil


# %%
import generate_readme


# %%
class TestGenerateReadMe(unittest.TestCase):
    def setUp(self):
        self.tmp_fold = "./tmp"
        if os.path.exists(self.tmp_fold):
            shutil.rmtree(self.tmp_fold)
        os.mkdir(self.tmp_fold)
        for i in range(1, 10):
            with open("{}/{}.jpg".format(self.tmp_fold, i), "w") as f:
                f.write("0000")
    
    def tearDown(self):
        shutil.rmtree(self.tmp_fold)
    
    def test_search_pic(self):
        pic_list = generate_readme.search_pic(self.tmp_fold)
        self.assertEqual(len(pic_list), len(list(range(1, 10))))
        
    def test_single_pic_html(self):
        html = """> ## **{}**\n![{}]({})\n<hr>\n""".format(1, 1, self.tmp_fold + os.sep + "1.jpg")
        pic_html = generate_readme.single_pic_html(self.tmp_fold + os.sep + "1.jpg")
        self.assertEqual(pic_html, html)
        
    def test_genrate_readme(self):
        t_html = generate_readme.generate_readme(self.tmp_fold)
        print(t_html)
        


# %%
if __name__ == "__main__":
    unittest.main()
